package com.sunchen.asc.application.rest;

import com.sunchen.asc.service.common.ResultResponse;
import com.sunchen.asc.service.item.api.ItemDepartmentService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item/department")
public class ItemDepartmentRest {

    @DubboReference
    ItemDepartmentService itemDepartmentService;

    @ApiOperation(value = "获得全部事项受派部门")
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public ResultResponse all(){
        return itemDepartmentService.all();
    }

    @ApiOperation(value = "创建事项受派部门")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "名称",required = true),
            @ApiImplicitParam(name="code",value = "编码",required = true),
            @ApiImplicitParam(name="parentId",value = "父级id",required = false),
            @ApiImplicitParam(name="description",value = "描述",required = false)
    })
    @RequestMapping(value = "/create",method = RequestMethod.GET)
    public ResultResponse create(@RequestParam String name,@RequestParam String code,@RequestParam(required = false) Long parentId,@RequestParam(required = false) String description){

        if (null == parentId){
            parentId = 0L;
        }
        return itemDepartmentService.create(name,code,parentId,description);
    }

    @ApiOperation(value = "修改事项受派部门")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "部门id",required = true),
            @ApiImplicitParam(name="name",value = "名称",required = true),
            @ApiImplicitParam(name="code",value = "编码",required = true),
            @ApiImplicitParam(name="description",value = "描述",required = false)
    })
    @RequestMapping(value = "/edit",method = RequestMethod.GET)
    public ResultResponse edit(@RequestParam Long id,@RequestParam String name,@RequestParam String code,@RequestParam(required = false) String description){

        return itemDepartmentService.edit(id,name,code,description);
    }

    @ApiOperation(value = "删除事项受派部门")
    @ApiImplicitParam(name="id",value = "部门id",required = true)
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public ResultResponse delete(@RequestParam Long id){
        return itemDepartmentService.delete(id);
    }
}
